package com.yoyo.schedule.task_manager;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import lombok.Getter;
import lombok.Setter;

import java.util.List;


public class TaskType implements java.io.Serializable {

    private static final long serialVersionUID = 1L;
    public static String status_pause = "pause";
    public static String status_resume = "resume";
    @Setter
    @Getter
    private String baseTaskType;
    @Setter
    @Getter
    private long heartBeatRate = 5 * 1000;
    @Setter
    @Getter
    private long judgeDeadInterval = 1 * 60 * 1000;
    @Setter
    @Getter
    private int sleepTimeNoData = 500;
    @Setter
    @Getter
    private int sleepTimeInterval = 0;
    @Setter
    @Getter
    private int fetchNumber = 500;
    @Setter
    @Getter
    private int maxExecuteNumber = 1;
    @Setter
    @Getter
    private int threadNumber = 5;
    @Setter
    @Getter
    private String processorType = "SLEEP";
    @Setter
    @Getter
    private String planRunStartTime;
    @Setter
    @Getter
    private String planRunEndTime;
    @Setter
    @Getter
    private double expireOwnSignInterval = 1;
    @Setter
    @Getter
    private String dealBeanName;
    @Setter
    @Getter
    private String taskParameter;
    @Setter
    @Getter
    private String[] taskItems;
    @Setter
    @Getter
    private int maxTaskItemsOfOneThreadGroup = 0;
    @Setter
    @Getter
    private long version;
    /**
     * pause,resume
     */
    @Setter
    @Getter
    private String status = status_resume;

    //gson {{index:1,data:{type=1,kind=1}},{}}
    public static String[] splitTaskItem(String string) {


        Gson gson = new Gson();
        List<TaskItemData> list = gson.fromJson(string, new TypeToken<List<TaskItemData>>() {
        }.getType());


        String[] ss = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {

            ss[i] = list.get(i).getData();

        }
        return ss;

    }


    public void setPlanRunStartTime(String planRunStartTime) {
        this.planRunStartTime = planRunStartTime;
        if (this.planRunStartTime != null && this.planRunStartTime.trim().length() == 0) {
            this.planRunStartTime = null;
        }
    }

    public void setPlanRunEndTime(String planRunEndTime) {
        this.planRunEndTime = planRunEndTime;
        if (this.planRunEndTime != null && this.planRunEndTime.trim().length() == 0) {
            this.planRunEndTime = null;
        }

    }

}
